package 双指针;

public class 移动零1 {
    //dest才是边界维护的指针，一个指针划分两部分，而cur是用来遍历的普通普遍指针
    public void moveZeroes1(int[] nums) {
        //https://leetcode.cn/problems/move-zeroes/description/
        int cur = 0;
        int dest = -1;//用nums[dest]一定是dest先++ 再nums[dest]赋值的
        while (cur < nums.length) {
            if (nums[cur] != 0) {
                dest++;
                int tmp = nums[cur];
                nums[cur] = nums[dest];
                nums[dest] = tmp;
            }
            cur++;
        }
    }
    public void moveZeroes(int[] nums) {
        for (int cur = 0,dest = -1;cur < nums.length;cur++) {
            if (nums[cur] != 0) {
                dest++;
                int tmp = nums[cur];
                nums[cur] = nums[dest];
                nums[dest] = tmp;
            }
        }
    }
}
